package com.shorturl.controller;

import com.shorturl.beans.UrlModel;
import com.shorturl.beans.Urls;
import com.shorturl.services.UrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private Urls urls;

    @RequestMapping("")
    public String index(){

        UrlService urlService = new UrlService(urls.getDBCollection());

        List<UrlModel> list = urlService.getUrls(10);

        for (UrlModel model : list) {
            System.out.println(model);
        }

        UrlModel urlModel = new UrlModel();
        urlModel.setKey("AAAAAA");
        urlModel.setUrl("http://www.baidu.com");
        urlModel.setAddTime(new Date());
        urlModel.setUserId(0);

        urlService.save(urlModel);

        return "hello";
    }
}
